﻿<%@ Page  MasterPageFile="~/Site.Master" Language="C#" AutoEventWireup="true" CodeBehind="ShipRuleAdd.aspx.cs" Inherits="RabbitManage.UI.ShipRuleAdd" %>

<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent">
    <form id="form1" action="../Action/ShipRuleAdd.aspx" method="POST">
        
        <h3>运费策略新增:</h3>

        <script type="text/javascript">

            form1.onsubmit = function (e) {
                e.preventDefault();

                var data = [];
                for (var i = 0, ii = form1.length; i < ii; ++i) {
                    var input = form1[i];
                    if (input.name) {
                        if (input.name == "firstCost") {
                            var cost = {};
                            cost["Region"] = input.id;
                            cost["Cost"] = input.value;
                            data.push(cost);
                        }
                    }
                }

                var xhr = new XMLHttpRequest();
                xhr.open(form1.method, form1.action, true);
                xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');

                xhr.send(JSON.stringify(data));

                xhr.onloadend = function () {
                    // done
                    if (xhr.responseText == "true") {
                        window.location = "/UI/ShipRuleShow.aspx";
                    } else {
                        alert(xhr.responseText);
                    }
                };
            };
            
            var afar = '<%=provinceAfar %>';
            
            function SetAll() {
                var result = document.getElementById('inputBaseCost').value;
                var inputs = document.getElementsByName('firstCost');
                for (var i = 0; i < inputs.length; i++) {
                    inputs[i].value = result;
                }
            }
            function SetAfar() {
                var result = document.getElementById('inputBaseCost').value;
                var inputs = document.getElementsByName('firstCost');
                for (var i = 0; i < inputs.length; i++) {
                    var input = inputs[i];
                    if (afar.indexOf(input.id) == -1) {
                         
                    } else {
                        input.value = result;
                    }
                }
            }
            function SetNear() {
                var result = document.getElementById('inputBaseCost').value;
                var inputs = document.getElementsByName('firstCost');
                for (var i = 0; i < inputs.length; i++) {
                    var input = inputs[i];
                    if (afar.indexOf(input.id) == -1) {
                        input.value = result;
                    }
                }
            }

            function CheckAll() {
                var result = document.getElementById('selectAll').checked;
                var inputs = document.getElementsByName('selectedProvince');
                for (var i = 0; i < inputs.length; i++) {
                    inputs[i].checked = result;
                }
            }

            function CheckReverse() {
                var inputs = document.getElementsByName('selectedProvince');
                for (var i = 0; i < inputs.length; i++) {
                    inputs[i].checked = !inputs[i].checked;
                }
            }

            
            function CheckNear() {
                var inputs = document.getElementsByName('selectedProvince');
                for (var i = 0; i < inputs.length; i++) {
                    var input = inputs[i];
                    if (afar.indexOf(input.value) == -1) {
                        input.checked = true;
                    } else {
                        input.checked = false;
                    }
                }
            }
        </script>
        <script type="text/javascript" src="/Share/js/city.js"></script>
        
        <table>
            <tr>
                <td>
                    <table>
                        <tr>
                            <td>省份</td>
                            <td>首重</td>
                            <%--<td>续重</td>--%>
                        </tr>
                        <asp:Repeater runat="server" ID="costRepeater" >
                            <ItemTemplate>
                                <tr>
                                    <td><%#Eval("Key") %></td>
                                    <td><input type="text" id="<%#Eval("Key") %>" name="firstCost" value="<%#Eval("Value") %>" style="width: 40px; text-align: right;" /></td>
                                    <%--<td><input type="text" name="<%#Eval("Name") %>" /></td>--%>
                                </tr>
                            </ItemTemplate>
                        </asp:Repeater>
            
            
<%--                        <asp:Repeater runat="server" ID="ruleRepeater" >
                            <ItemTemplate>
                                <tr>
                                    <td><%#Eval("Key") %></td>
                                    <td><%#Eval("Value") %></td>
                                </tr>
                            </ItemTemplate>
                        </asp:Repeater>--%>
                    </table>
                </td>
                
                <td style="vertical-align: top;">
                    <h3>批量设置</h3>
                    <table style="vertical-align: top;">
                       <%-- <tr>
                            <td>
                                规则名称：
                            </td>
                            <td>
                                <input type="text" id="inputStrategyName" name="StrategyName"  value="<%=stragegyName %>" />
                            </td>
                        </tr>--%>
                        <tr>
                            <td>
                                运费：
                            </td>
                            <td>
                                <input type="text" id="inputBaseCost" name="BaseCost" style="width: 40px; text-align: right;" value="<%=cost %>" />
                            </td>
                        </tr>
<%--                        <tr>
                            <td>
                                续重：
                            </td>
                            <td>
                                <input type="text" id="inputKgCost" name="KgCost" style="width: 40px; text-align: right;" value="<%=cost %>" />
                            </td>
                        </tr>--%>

                    </table>
                    
                    范围：
                    <input type="button" onclick="SetAll();"  value="全国" />
                    <input type="button" onclick="SetAfar();" value="偏远省份" />
                    <input type="button" onclick="SetNear();" value="偏远除外" />
                    <br/>
                    <input type="submit" value="保存" />
                </td>
            </tr>
        </table>
        
    </form>
    
</asp:Content>